package com.example.diffservice.controller;

import com.example.common.core.AjaxResult;
import com.example.diffservice.entity.vo.GitInfo;
import com.example.common.utils.GitUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author DestinyCc
 * @date 2022/4/13
 */
@RestController
@RequestMapping("/git")
public class GitController {

    @PostMapping("/clone")
    public AjaxResult clone(@RequestBody GitInfo gitInfo){
        try {
            GitUtils.clone(gitInfo.getOwner(), gitInfo.getRepo());
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }
    }

    @PostMapping("/pull")
    public AjaxResult pull(@RequestBody GitInfo gitInfo){
        try {
            GitUtils.pull(gitInfo.getOwner(), gitInfo.getRepo());
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }
    }
}
